from typing import List
import numpy as np


def evaluate_features(windows: List[np.ndarray]):
    """Placeholder for TCN-Transformer model inference.
    We compute simple statistics across windows and map to [0,100] score
    and an anomaly probability based on jerk/variance metrics.
    """
    if not windows:
        return 50.0, 0.5

    # Aggregate features: mean abs value per channel and variance
    means = []
    variances = []
    jerks = []  # approximate derivative magnitude
    for w in windows:
        abs_mean = np.abs(w).mean(axis=0).mean()
        var = w.var(axis=0).mean()
        # jerk as mean absolute diff across time
        jerk = np.abs(np.diff(w, axis=0)).mean()
        means.append(abs_mean)
        variances.append(var)
        jerks.append(jerk)

    m = float(np.mean(means))
    v = float(np.mean(variances))
    j = float(np.mean(jerks))

    # Map to score: higher controlled movement (lower jerk, moderate variance) -> higher score
    # Normalize components safely
    j_norm = 1.0 / (1.0 + j)
    v_norm = 1.0 / (1.0 + abs(v - 1.0))  # prefer variance near 1 after normalization
    base_score = 60.0 * j_norm + 40.0 * v_norm
    score = max(0.0, min(100.0, base_score))

    # Anomaly probability: high jerk or very high variance
    anomaly_raw = (j / (j + 1.0)) * 0.6 + (v / (v + 1.0)) * 0.4
    anomaly_prob = max(0.0, min(1.0, anomaly_raw))

    return round(score, 2), round(anomaly_prob, 3)